package cn.tlb.ui.sdk_widget;

import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;

import cn.tlb.xutilsdownload.R;

public class SimpleCropViewActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_simple_crop_view);

        final CropImageView cropImageView = (CropImageView)findViewById(R.id.cropImageView);
        final ImageView croppedImageView = (ImageView)findViewById(R.id.croppedImageView);

        // Set image for cropping
        cropImageView.setImageBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.sample1));
        cropImageView.rotateImage(CropImageView.RotateDegrees.ROTATE_180D);
        cropImageView.setCropMode(CropImageView.CropMode.RATIO_FREE);
        cropImageView.setMinFrameSizeInDp(100);

        //colors
        cropImageView.setBackgroundColor(0xFFFFFF00);
        cropImageView.setOverlayColor(0xAA1C1C1C);
        cropImageView.setFrameColor(0xFF86C166);
        cropImageView.setHandleColor(0xFF86C166);
        cropImageView.setGuideColor(0xaa86C166);

        //size
        cropImageView.setFrameStrokeWeightInDp(1);
        cropImageView.setGuideStrokeWeightInDp(1);
        cropImageView.setHandleSizeInDp(8);
        // 控制Handle的触摸区域半径 16dp
        cropImageView.setTouchPaddingInDp(16);

        //Handle and Guide ShowMode
        cropImageView.setHandleShowMode(CropImageView.ShowMode.SHOW_ALWAYS);
        cropImageView.setGuideShowMode(CropImageView.ShowMode.SHOW_ON_TOUCH);



        Button cropButton = (Button)findViewById(R.id.crop_button);
        cropButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                // Get cropped image, and show result.
                croppedImageView.setImageBitmap(cropImageView.getCroppedBitmap());
            }
        });
    }
}
